Skip to content

Fix twig_compare float-string trailing whitespace + refactor#3256

Merged
fabpot merged 1 commit into
twigphp:3.xfrom
guilliamxavier:patch-1
Jun 8, 2020
Merged

Fix twig_compare float-string trailing whitespace + refactor#3256
fabpot merged 1 commit into
twigphp:3.xfrom
guilliamxavier:patch-1

Conversation

@guilliamxavier

@guilliamxavier guilliamxavier commented Feb 4, 2020

Copy link
Copy Markdown
Contributor

Fixes #3345

Refs #2966 (and #3186)

(feel free to discard the "Factorize" commit if you favor performance over maintainability)

@fabpot

fabpot commented Feb 11, 2020

Copy link
Copy Markdown
Contributor

Can you revert the Factorize commit?

@guilliamxavier

Copy link
Copy Markdown
Contributor Author

@fabpot: Done.


[0, 42.0, ' 42.0'],
[0, 42.0, '42.0 '],
[-1, 42.0, '42.0abc'],

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PHP 8 returns 0

@guilliamxavier guilliamxavier May 30, 2020

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@fabpot: But that's unrelated to this PR. Indeed, php/php-src#3886 hasn't been merged (yet), so several existing tests currently return a different result (https://3v4l.org/dX6Q9/rfc#output).

Comment thread tests/Extension/CoreTest.php
@fabpot

fabpot commented Jun 8, 2020

Copy link
Copy Markdown
Contributor

Thank you @guilliamxavier.

@fabpot fabpot merged commit 83d6a12 into twigphp:3.x Jun 8, 2020
@guilliamxavier guilliamxavier deleted the patch-1 branch June 8, 2020 12:00
if (is_nan($b)) {
return 1;
}
$a = trim($a);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wouldn't this trimming cause issue when entering this !is_numeric($a) and comparing strings ? Shouldn't we compare the original string then ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@stof: I think you are right and there was already the problem for int <=> string above (see https://3v4l.org/RIUI5). Open a new issue/PR?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@stof: See #3352

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3.0 regression/inconsistency when comparing a float to a numeric string with trailing space

4 participants